package com.chixing.dao.impl;

import com.chixing.dao.DepartmentDao;
import com.chixing.entity.Department;

import java.util.List;

public class DepartDaoImpl implements DepartmentDao {
    private JDBCTemplate<Department> jdbcTemplate  = new JDBCTemplate<>(new DepartmentRowMapper());
    public int insert(Department department) {
        String sql = "insert into department values(?,?,?)";
        Object[] args = {department.getDeptNo(), department.getDeptName(), department.getLoc()};
        return jdbcTemplate.update(sql, args);
    }
    public int update(Department department) {
        String sql = "update department set dept_name = ?, loc = ? where dept_no = ?";
        Object[] args = {department.getDeptName(), department.getLoc(), department.getDeptNo()};
        return jdbcTemplate.update(sql, args);
    }
    public int delete(int DeptNo) {
        String sql = "delete from department where dept_no = ?";
        return jdbcTemplate.update(sql, DeptNo);
    }
    public Department selectById(int DeptNo) {
        String sql = "select deptno , dname ,loc from department where dept_no = ?";
        return jdbcTemplate.selectForObject(sql, DeptNo);
    }
    public List<Department> selectAll() {
        String sql = "select deptno , dname ,loc rom department";
        return jdbcTemplate.selectForList(sql);
    }

}
